<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>原生ajax</title>
</head>
<body>
<input type="button" value="获取数据" onclick="getData()">

<div id="div1"></div>
<script>
     function getData(){
         console.log(123)
         let xmlHttpRequest =new XMLHttpRequest();
         xmlHttpRequest.open('GET','data.json');
         xmlHttpRequest.send();
         xmlHttpRequest.onreadystatechange=function (){
             if(xmlHttpRequest.readyState=== 4&&xmlHttpRequest.status===200){
                 document.getElementById('div1').innerHTML=xmlHttpRequest.responseText;
             }
         }
     }
</script>
</body>
</html>